import React, {Component} from 'react';
import {BackHandler, Platform, StatusBar, View} from 'react-native';

export default class BaseComponent extends Component {
    componentWillMount(): void {
        Log(this.props.navigation.state.routeName+"：componentWillMount()");
    }

    componentDidMount(): void {
        Log(this.props.navigation.state.routeName+"：componentDidMount()");
        if(Platform.OS === "android"){
            BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
        }else if (Platform.OS === "ios") {
            Log("ios add eventListener");
        }else {
            Log("neither");
        }

    }

    componentWillUpdate(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): void {
        Log(this.props.navigation.state.routeName+"：componentWillUpdate()");
    }

    componentWillUnmount(): void {
        Log(this.props.navigation.state.routeName+"：componentWillUnmount()");
        BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
    }


    handleBackPress = () => {
        // 判断界面routeName可以针对某界面的物理返回键进行处理
        /*if(this.props.navigation.state.routeName==="Page1"){
            Log("退出整个应用");
            //BackHandler.exitApp();//退出整个应用
        }else {
            Log("小退一步");
        }*/
    };

}